home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / elv18src.zip / vi.h < prev    next >
C/C++ Source or Header  |  1994-01-29  |  27KB  |  678 lines

  1. /* vi.h */
  2.  
  3. /* Author:
  4.  *    Steve Kirkendall
  5.  *    14407 SW Teal Blvd. #C
  6.  *    Beaverton, OR 97005
  7.  *    kirkenda@cs.pdx.edu
  8.  */
  9.  
  10. #define VERSION "ELVIS 1.8pl1, by Steve Kirkendall (29 January 1994)"
  11. #define COPYING    "This version of ELVIS is freely redistributable."
  12.  
  13. #include <errno.h>
  14. #if TOS
  15. # ifndef __GNUC__
  16. #  define ENOENT (-AEFILNF)
  17. # endif
  18. #endif
  19.  
  20. #if TOS || VMS
  21. # include <types.h>
  22. # define O_RDONLY    0
  23. # define O_WRONLY    1
  24. # define O_RDWR        2
  25. # ifdef __GNUC__
  26. #  define S_IJDIR    S_IFDIR
  27. # endif
  28. #else
  29. # if OSK
  30. #  include <modes.h>
  31. #  define O_RDONLY    S_IREAD
  32. #  define O_WRONLY    S_IWRITE
  33. #  define O_RDWR    (S_IREAD | S_IWRITE)
  34. #  define ENOENT    E_PNNF
  35. #  define sprintf    Sprintf
  36. # else
  37. #  if !AMIGA
  38. #   include <sys/types.h>
  39. #  endif
  40. #  if COH_286
  41. #   include <sys/fcntl.h>
  42. #  else
  43. #   include <fcntl.h>
  44. #  endif
  45. # endif
  46. #endif
  47.  
  48. #ifndef O_BINARY
  49. # define O_BINARY    0
  50. #endif
  51.  
  52. #include "curses.h"
  53.  
  54. #include <signal.h>
  55. #ifdef __STDC__
  56. # include <stdio.h>    /* for [v]sprintf prototype        */
  57. # include <string.h>    /* for str* prototypes            */
  58. # include <stdlib.h>    /* for atoi, system, malloc, free    */
  59. # include <stdarg.h>    /* for vararg definitions        */
  60. # ifdef NeXT
  61. #  include <libc.h>
  62. # else
  63. #  if ANY_UNIX
  64. #   include <unistd.h>    /* for read, write, ... prototypes      */
  65. #   include <sys/wait.h>/* for wait prototype                   */
  66. #  endif
  67. # endif
  68. #endif
  69.  
  70. #if TURBOC
  71. # include <string.h>
  72. # include <stdarg.h>    /* for vararg definitions        */
  73. #endif
  74.  
  75. /*------------------------------------------------------------------------*/
  76. /* Miscellaneous constants.                          */
  77.  
  78. #define INFINITY    2000000001L    /* a very large integer */
  79. #define LONGKEY        10        /* longest possible raw :map key */
  80. #ifndef MAXRCLEN
  81. # define MAXRCLEN    1000        /* longest possible :@ command */
  82. #endif
  83.  
  84. /*------------------------------------------------------------------------*/
  85. /* These describe how temporary files are divided into blocks             */
  86.  
  87. #define MAXBLKS    (BLKSIZE / sizeof(unsigned short))
  88. typedef union
  89. {
  90.     char        c[BLKSIZE];    /* for text blocks */
  91.     unsigned short    n[MAXBLKS];    /* for the header block */
  92. }
  93.     BLK;
  94.  
  95. /*------------------------------------------------------------------------*/
  96. /* These are used manipulate BLK buffers.                                 */
  97.  
  98. extern BLK    hdr;        /* buffer for the header block */
  99. extern BLK *blkget P_((int));    /* given index into hdr.c[], reads block */
  100. extern BLK *blkadd P_((int));    /* inserts a new block into hdr.c[] */
  101.  
  102. /*------------------------------------------------------------------------*/
  103. /* These are used to keep track of various flags                          */
  104. extern struct _viflags
  105. {
  106.     short    file;        /* file flags */
  107. }
  108.     viflags;
  109.  
  110. /* file flags */
  111. #define NEWFILE        0x0001    /* the file was just created */
  112. #define READONLY    0x0002    /* the file is read-only */
  113. #define HADNUL        0x0004    /* the file contained NUL characters */
  114. #define MODIFIED    0x0008    /* the file has been modified, but not saved */
  115. #define ADDEDNL        0x0010    /* newlines were added to the file */
  116. #define HADBS        0x0020    /* backspace chars were lost from the file */
  117. #define UNDOABLE    0x0040    /* file has been modified */
  118. #define NOTEDITED    0x0080    /* the :file command has been used */
  119.  
  120. /* macros used to set/clear/test flags */
  121. #define setflag(x,y)    viflags.x |= y
  122. #define clrflag(x,y)    viflags.x &= ~y
  123. #define tstflag(x,y)    (viflags.x & y)
  124. #define initflags()    viflags.file = 0;
  125.  
  126. /* The options */
  127. extern char    o_autoindent[1];
  128. extern char    o_autoprint[1];
  129. extern char    o_autotab[1];
  130. extern char    o_autowrite[1];
  131. extern char    o_columns[3];
  132. extern char    o_directory[30];
  133. extern char    o_edcompatible[1];
  134. extern char    o_equalprg[80];
  135. extern char    o_errorbells[1];
  136. extern char    o_exrefresh[1];
  137. extern char    o_ignorecase[1];
  138. extern char    o_keytime[3];
  139. extern char    o_keywordprg[80];
  140. extern char    o_lines[3];
  141. extern char    o_list[1];
  142. extern char    o_number[1];
  143. extern char    o_readonly[1];
  144. extern char    o_remap[1];
  145. extern char    o_report[3];
  146. extern char    o_scroll[3];
  147. extern char    o_shell[60];
  148. extern char    o_shiftwidth[3];
  149. extern char    o_sidescroll[3];
  150. extern char    o_sync[1];
  151. extern char    o_tabstop[3];
  152. extern char    o_term[30];
  153. extern char    o_flash[1];
  154. extern char    o_warn[1];
  155. extern char    o_wrapscan[1];
  156.  
  157. #ifndef CRUNCH
  158. extern char    o_beautify[1];
  159. extern char    o_exrc[1];
  160. extern char    o_mesg[1];
  161. extern char    o_more[1];
  162. extern char    o_nearscroll[3];
  163. extern char    o_newfile[1];
  164. extern char    o_novice[1];
  165. extern char    o_optimize[1];
  166. extern char    o_prompt[1];
  167. extern char    o_taglength[3];
  168. extern char    o_tags[256];
  169. extern char    o_terse[1];
  170. extern char    o_window[3];
  171. extern char    o_wrapmargin[3];
  172. extern char    o_writeany[1];
  173. #endif
  174.  
  175. #ifndef NO_ERRLIST
  176. extern char    o_cc[30];
  177. extern char    o_make[30];
  178. #endif
  179.  
  180. #ifndef NO_CHARATTR
  181. extern char    o_charattr[1];
  182. #endif
  183.  
  184. #ifndef NO_DIGRAPH
  185. extern char    o_digraph[1];
  186. extern char    o_flipcase[80];
  187. #endif
  188.  
  189. #ifndef NO_SENTENCE
  190. extern char    o_hideformat[1];
  191. #endif
  192.  
  193. #ifndef NO_EXTENSIONS
  194. extern char    o_inputmode[1];
  195. extern char    o_ruler[1];
  196. #endif
  197.  
  198. #ifndef NO_MAGIC
  199. extern char    o_magic[1];
  200. #endif
  201.  
  202. #ifndef NO_MODELINES
  203. extern char    o_modelines[1];
  204. #endif
  205.  
  206. #ifndef NO_SENTENCE
  207. extern char    o_paragraphs[30];
  208. extern char    o_sections[30];
  209. #endif
  210.  
  211. #if MSDOS
  212. extern char    o_pcbios[1];
  213. extern char    o_controlz[1];
  214. #endif
  215.  
  216. #if OS2
  217. extern char    o_viomode[1];
  218. #endif
  219.  
  220. #ifndef NO_SHOWMATCH
  221. extern char    o_showmatch[1];
  222. #endif
  223.  
  224. #ifndef    NO_SHOWMODE
  225. extern char    o_smd[1];
  226. #endif
  227.  
  228. #ifndef NO_TAGSTACK
  229. extern char    o_tagstack[1];
  230. #endif
  231.  
  232. #ifdef DEBUG
  233. extern char    o_slowmacro[1];
  234. #endif
  235.  
  236. /*------------------------------------------------------------------------*/
  237. /* These help support the single-line multi-change "undo" -- shift-U      */
  238.  
  239. extern char    U_text[BLKSIZE];
  240. extern long    U_line;
  241.  
  242. /*------------------------------------------------------------------------*/
  243. /* These are used to refer to places in the text               */
  244.  
  245. typedef long    MARK;
  246. #define markline(x)    (long)((x) / BLKSIZE)
  247. #define markidx(x)    (int)((x) & (BLKSIZE - 1))
  248. #define MARK_UNSET    ((MARK)0)
  249. #define MARK_FIRST    ((MARK)BLKSIZE)
  250. #define MARK_LAST    ((MARK)(nlines * BLKSIZE))
  251. #define MARK_EOF    ((MARK)((nlines + 1) * BLKSIZE - 1L))    /* -g.t. */
  252. #define MARK_AT_LINE(x)    ((MARK)(x) * BLKSIZE)
  253.  
  254. #define NMARKS    29
  255. extern MARK    mark[NMARKS];    /* marks a-z, plus mark ' and two temps */
  256. extern MARK    cursor;        /* mark where line is */
  257.  
  258. /*------------------------------------------------------------------------*/
  259. /* These are used to keep track of the current & previous files.      */
  260.  
  261. extern long    origtime;    /* modification date&time of the current file */
  262. extern char    origname[256];    /* name of the current file */
  263. extern char    prevorig[256];    /* name of the preceding file */
  264. extern long    prevline;    /* line number from preceding file */
  265.  
  266. /*------------------------------------------------------------------------*/
  267. /* misc housekeeping variables & functions                  */
  268.  
  269. extern int    tmpfd;                /* fd used to access the tmp file */
  270. extern int    tmpnum;                /* counter used to generate unique filenames */
  271. extern long    lnum[MAXBLKS];            /* last line# of each block */
  272. extern long    nlines;                /* number of lines in the file */
  273. extern char    args[BLKSIZE];            /* file names given on the command line */
  274. extern int    argno;                /* the current element of args[] */
  275. extern int    nargs;                /* number of filenames in args */
  276. extern long    changes;            /* counts changes, to prohibit short-cuts */
  277. extern int    significant;            /* boolean: was a *REAL* change made? */
  278. extern int    exitcode;            /* 0=not updated, 1=overwritten, else error */
  279. extern BLK    tmpblk;                /* a block used to accumulate changes */
  280. extern long    topline;            /* file line number of top line */
  281. extern int    leftcol;            /* column number of left col */
  282. #define        botline     (topline + LINES - 2)
  283. #define        rightcol (leftcol + COLS - (*o_number ? 9 : 1))
  284. extern int    physcol;            /* physical column number that cursor is on */
  285. extern int    physrow;            /* physical row number that cursor is on */
  286. extern int    exwrote;            /* used to detect verbose ex commands */
  287. extern int    doingdot;            /* boolean: are we doing the "." command? */
  288. extern int    doingglobal;            /* boolean: are doing a ":g" command? */
  289. extern long    rptlines;            /* number of lines affected by a command */
  290. extern char    *rptlabel;            /* description of how lines were affected */
  291. extern char    *fetchline P_((long));        /* read a given line from tmp file */
  292. ex